<!doctype html>
<html class="no-js" manifest="__PUBLIC__/home/manifest/test.manifest">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <title>我要投稿</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="绵阳中学英才学校" />
    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileColor" content="#0e90d2">
    <link rel="stylesheet" href="__PUBLIC__/home/css/amazeui.min.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/contribute.css">
    <link rel="stylesheet" href="__PUBLIC__/home/css/registrationform.css">
</head>
<body>
    <!-- 头部 -->
    <header data-am-widget="header" class="am-header am-header-default">
      <div class="am-header-left am-header-nav">
        <a href="javascript:history.go(-1);" class="am-header-left1">
          <img src="__PUBLIC__/home/images/back.png" alt="">
        </a>
      </div>

      <h3 class="am-header-title">
          <a href="#title-link" class="">
            我要投稿
          </a>
      </h3>

      <div class="am-header-right am-header-nav index_denglu">
        <if condition="$_SESSION['login'] eq 1" >
        <a href="{:U('User/user_center')}" class="am-header-right1">
         	 个人中心
        </a>
       	<else/>
       	<a href="{:U('Login/login')}" class="am-header-right1">
         	 登录
        </a>
        </if>
      </div>
    </header>

    <!-- 中间 -->
    <div class="content">
    	<input type="hidden" value="{$_SESSION['user_id']}" id="user_id">
      <div class="content1">标注*为必填项</div>
      <div class="content2">
        <div class="content2_title am-g">
            <div class="am-u-sm-3">
              <div><span>*</span> <h3>标&nbsp;题</h3></div>
            </div>
            <div class="am-u-sm-9">
              <input name="title" type="text">
            </div>
        </div>
        <div class="content2_title am-g">
            <div class="am-u-sm-3">
              <div><span>*</span> <h3>作&nbsp;者</h3></div>
            </div>
            <div class="am-u-sm-9">
              <input name="editor" type="text">
            </div>
        </div>
        <div class="content2_title am-g">
            <div class="am-u-sm-3">
              <div><span>*</span> <h3>摘&nbsp;要</h3></div>
            </div>
            <div class="am-u-sm-9">
              <input name="abstract" type="text">
            </div>
        </div>
        <div class="content2_title am-g">
            <div class="am-u-sm-3">
              <div><span>*</span> <h3>&nbsp;身&nbsp;份</h3></div>
            </div>
            <div class="am-u-sm-9">
              <select class="shenfen" name="role_id">
                <option value="1">教师</option>
                <option value="2">家长</option>
                <option value="3">学生</option>
              </select>
            </div>
        </div>
        <div class="content2_title am-g content2_title_out">
            <div class="am-u-sm-3">
              <div><span>*</span> <h3>&nbsp;专&nbsp;区</h3></div>
            </div>
            <div class="am-u-sm-9">
              <select class="shenfen zhuanqu" name="ac_id">
                <option value="4">初一专区</option>
                <option value="5">初二专区</option>
                <option value="6">初三专区</option>
              </select>
            </div>
        </div>
      </div>
      <div class="content3">
        <div class="content2_title am-g content2_title_out">
            <div class="am-u-sm-12">
              <div class="content3_title"><span>*</span> <h3>正&nbsp;文</h3></div>
            </div>
            <div class="am-u-sm-12 content3_text content3_texts">
              <textarea name="content" rows="5" cols="">
                
              </textarea>
            </div>
            <div class="am-u-sm-12 content3_text camera">
              <!-- 添加后显示的图片 -->
             	 <div class="prize">
                </div>
                <!-- 添加图片 -->
                <div id="file" class="am-u-sm-4">
                  <img src="__PUBLIC__/home/images/camera.png" alt="" class="filebtn file_img_out"/>
                  <input class='upfile' id="prize_pic" name="prize_pic" type="file" multiple/>
                </div>
            </div>
        </div>
      </div>
      <div class="content4 am-g">
        <div class="am-u-sm-6">
          <button id="save">保存草稿</button>
        </div>
        <div class="am-u-sm-6">
          <button id="send">发送投稿</button>
        </div>
      </div>
      <div class="content5 am-g">
        <div class="am-u-sm-11">
            【注】转载请标明出处
        </div>
      </div>
    </div>

    <script src="__PUBLIC__/home/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/js/amazeui.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.ui.widget.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="__PUBLIC__/home/js/jquery.fileupload.js"></script>
    <script>
  //表单验证
	function check_form(){
		if($("input[name=title]").val() == ''){
			alert('标题不能为空');
			$("input[name=title]").focus();
			return false;
		}
		if($("input[name=abstract]").val() == ''){
			alert('摘要不能为空');
			$("input[name=abstract]").focus();
			return false;
		}
		if($("input[name=editor]").val() == ''){
			alert('请填编辑者');
			$("input[name=editor]").focus();
			return false;
		}
		if($("input[name=content]").val() == ''){
			alert('请填写内容');
			$("input[name=content]").focus();
			return false;
		}
		return true;
	}
      $(function(){
        $('.upfile').change(function(){
           $('#filetxt').val($('.upfile').val());
        });
        $('#prize_pic').fileupload({
            dataType: 'json',//数据类型：json
            url: '__APP__/Enroll/upload',//上传地址
            formData: {name:'prize_pic'},
            add: function (e,data) {
            	$("input[name=prize]").remove();
                data.submit();
            },
            done: function (e,data) {
                var param = data.result;
               if (typeof(param.error) != 'undefined') {
                    alert(param.error);//弹出错误
                }else{
                		var leng = param[0].savepath.length-1;
                		var html="<div class='file'><img src='__PUBLIC__/home/images/Delete.png' class='Delete_img'/><img src='__ROOT__"+param[0].savepath.substr(1,leng)+param[0].savename+"' />"+"<input type='hidden' name='pic' value='"+param[0].savepath.substr(1,leng)+param[0].savename+"' /></div>";
                		$('.prize').after(html);
               }
               $(".Delete_img").on('click',function(){
                   $(this).parent().remove();
                });
            }
        });
        /*发送投稿*/
        
        $("#send").click(function(){
        	var user_id = $('#user_id').val();
			if(!user_id){
				alert('请先登录');
				return;
			}
        	var values=new Array();
        	var title = $("input[name=title]").val();
        	var editor =$("input[name=editor]").val();
        	var con =$("textarea[name=content]").val();
        	var abs =$("input[name=abstract]").val();
        	var role_id = $("select[name=role_id] option:selected").val();
        	var ac_id = $("select[name=ac_id] option:selected").val();
        	$("input[name=pic]").each(function () {
                    values.push($(this).val());
                });
                values = values.join(",");
        	if(check_form()){
        		$.ajax({
        			type:"post",
        			url:"{:U('User/send_contri')}",
        			data:{'title':title,'editor':editor,'abstract':abs,'role_id':role_id,'ac_id':ac_id,'pic':values,'content':con},
        			success:function(data){
        				console.log(data);
        				if(data == 1){
        					alert('投稿成功');
        					window.location.href = '__APP__/User/user_center';
        				}else{
        					alert('失败');
        				}	
        			}
        		});
        	}
        });
        /*保存投稿*/
        $("#save").click(function(){
        	var user_id = $('#user_id').val();
			if(!user_id){
				alert('请先登录');
				return;
			}
        	var values=new Array();
        	var title = $("input[name=title]").val();
        	var editor =$("input[name=editor]").val();
        	var con =$("textarea[name=content]").val();
        	var abs =$("input[name=abstract]").val();
        	var role_id = $("select[name=role_id] option:selected").val();
        	var ac_id = $("select[name=ac_id] option:selected").val();
        	$("input[name=pic]").each(function () {
                    values.push($(this).val());
                });
                values = values.join(",");
        	if(check_form()){
        		$.ajax({
        			type:"post",
        			url:"{:U('User/draft_contri')}",
        			data:{'title':title,'abstract':abs,'editor':editor,'role_id':role_id,'ac_id':ac_id,'pic':values,'content':con,'user_id':user_id},
        			success:function(data){
        				console.log(data);
        				if(data == 1){
        					alert('保存成功');
        					window.location.href = '__APP__/User/user_center';
        				}else{
        					alert('失败');
        				}	
        			}
        		});
        	}
        });
      });
    </script>
</body>

</html>
